#!/usr/bin/env python3

###############################################################################
# Name:        IODebug
# Purpose:     A program to check the value of Slave-IO, it's also an Editor for config-files.
# Author:      Bright Li
# Modified by:
# Created:     2019-01-14
# Version:     [1.3.0]
# RCS-ID:      $$
# Copyright:   (c) Bright Li
# Licence:
###############################################################################

import sys
import argparse

import dbus
from dbus.mainloop.pyqt5 import DBusQtMainLoop

# 注意自定义模块的加载顺序~
import user.glob_var
from frw.entry import qt5_program_run
from gui.wx.mainvac import MainWndVac

from data.iotype import IO_TYPE

def getopt():
    parser = argparse.ArgumentParser("IODebug", description="IODebug [1.3.0] 2019-01-14")
    parser.add_argument("path_iotype", action="store", help="the path of iotype.yaml")
    parser.add_argument("-l", "--logging", action="store", type=int, help="the logging-level, default is logging.WARNING")
    parser.add_argument("-e", "--editers", action="store", help="list of conf-files to edit")
    return parser.parse_args()

# e.g.
# python3 main.py $CNC_CFG_DIR/iotype.yaml -e "['abc.yaml', 'bcd.yaml', ... ]"
args = getopt()

# 动态导入IO数据的类型定义
IO_TYPE.load_from_file(args.path_iotype)

logging_level = args.logging if args.logging else 10
list_edit_conf = eval(args.editers) if args.editers else False

qt5_program_run(MainWndVac, logging_level, list_edit_conf)
